package com.xfcycle.zebrabikegp.util;

import android.content.Context;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Properties;

/**
 * 处理从文件系统中获得的数据
 */
public class HandleDataByFileUtil {

    public void writePictureToCacheFile(byte[] pictureTemp, String filePath) {
        try {
            File file = new File(filePath);
            FileOutputStream fos = new FileOutputStream(file);
            fos.write(pictureTemp, 0, pictureTemp.length);
            fos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 从Properties文件中取数据，利用properties处理is流，文件路径为app/src/main/assets
     */
    public static String getDatafromProperties(String key,Context context) {

        String value = null;

        try {
            InputStream is = context.getClass().getClassLoader().getResourceAsStream("assets/config.properties");
            Properties props = new Properties();
            props.load(is);
            value = props.getProperty(key);
            is.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return value;
    }
}
